#!/usr/bin/env python2.5
# encoding: utf-8
"""
SQLImportStream.py

Created by Alakazam on 2007-07-05.
Copyright (c) 2007 . All rights reserved.
"""

from SQLStream import SQLStream

class SQLImportStream(SQLStream):
  def __init__(self, DBServer, name, query):
    super(SQLImportStream, self).__init__(DBServer, name)
    
    self.streamTableStructure = query
    
    try:
      self.DBServer.execute(
        "CREATE VIEW `" + self.name + "` AS " + self.streamTableStructure)
    except Exception:
      pass
  
  def __repr__(self):
    try:
      name = self.name
    except AttributeError:
      name = "Undefined"
    
    return "SQLImportStream('%s', '%s', structure='%s')"%(self.DBServer, name, self.streamTableStructure)
  
  def delete(self):
    self.DBServer.execute('DROP VIEW `' + self.name + '`');

